package main

import (
	"booksPro/controller"
	"booksPro/dao"
	"fmt"
	"net/http"
	"text/template"
)

func IndexHandler(w http.ResponseWriter, r *http.Request) {
	pageNo := r.FormValue("pageNo")
	if pageNo == "" {
		pageNo = "1"
	}
	fmt.Println("pageNo=", pageNo)
	page, _ := dao.GetPageBooks(pageNo)
	t := template.Must(template.ParseFiles("views/index.html"))
	t.Execute(w, page)
}
func main() {
	//给静态资源 映射url路径
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("views/static"))))
	http.Handle("/pages/", http.StripPrefix("/pages/", http.FileServer(http.Dir("views/pages"))))

	//首页映射路径
	http.HandleFunc("/index", controller.GetBooksByPrice)
	http.HandleFunc("/login", controller.Login)
	http.HandleFunc("/regist", controller.Regist)
	http.HandleFunc("/checkUserName", controller.CheckUserName)
	http.HandleFunc("/getBooks", controller.GetPageBooks)
	http.HandleFunc("/deleteBook", controller.DeleteBook)
	http.HandleFunc("/updateBook", controller.UpdateBook)
	http.HandleFunc("/toUpdateBook", controller.ToUpdateBook)
	http.HandleFunc("/getPageBooks", controller.GetPageBooks)
	http.HandleFunc("/getBooksByPrice", controller.GetBooksByPrice)
	http.HandleFunc("/logout", controller.Logout)
	http.HandleFunc("/addBook2Cart", controller.AddBook2Cart)
	http.HandleFunc("/toCarts", controller.ToCarts)
	http.HandleFunc("/deleteCart", controller.DeleteCart)
	http.HandleFunc("/deleteCartItem", controller.DeleteCartItem)
	http.HandleFunc("/updateCartItem", controller.UpdateCartItem)
	http.HandleFunc("/toPay", controller.ToPay)
	http.HandleFunc("/getOrders", controller.GetOrders)
	http.HandleFunc("/getOrderInfo", controller.GetOrderInfo)
	http.HandleFunc("/getMyOrder", controller.GetMyOrder)
	http.HandleFunc("/sendOrder", controller.SendOrder)
	http.HandleFunc("/takeOrder", controller.TakeOrder)
	http.HandleFunc("/takeOrder1", controller.TakeOrder)
	http.ListenAndServe(":8080", nil)

}
